package com.example.meterialproject.activitys.transition.demo6

import android.graphics.Color
import android.os.Bundle
import android.transition.TransitionInflater
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.core.view.ViewCompat
import androidx.fragment.app.Fragment
import coil.load
import com.example.meterialproject.R
import com.google.android.material.transition.MaterialContainerTransform
import kotlinx.android.synthetic.main.activity_transition_to_2.*
import java.util.concurrent.TimeUnit

/**
 *
 * @ClassName: TransitionDemo6ToFragment
 * @Author: android 超级兵
 * @CreateDate: 4/28/22$ 1:40 PM$
 * TODO
 */
class TransitionDemo6ToFragment : Fragment() {
    companion object {
        const val TRANSITION_NAME = "transition_name"
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View? {
        return inflater.inflate(R.layout.activity_transition_to_2, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        requireArguments().getString(TRANSITION_NAME)?.also {
            ViewCompat.setTransitionName(imagView, it)
            imagView.load(it)

            val transform = MaterialContainerTransform(requireContext(), true)
            transform.fadeMode = MaterialContainerTransform.FADE_MODE_OUT
            transform.scrimColor = Color.TRANSPARENT
            sharedElementEnterTransition = transform
        }
    }
}